package com.wjb.controller;

import com.wjb.pojo.dto.CouponDto;
import com.wjb.pojo.entity.Coupon;
import com.wjb.service.CouponService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author : 王济彬
 * @date: 2025/5/24 - 05 - 24 - 23:40
 * @Description: com.wjb.controller
 * @version: 1.0
 */
@RestController
public class CouponController {

    @Resource
    private CouponService couponService;

    @GetMapping("/createCoupon")
    public boolean createCoupon(@RequestBody CouponDto couponDto){
        String uuid = UUID.randomUUID().toString();
        Coupon coupon = new Coupon();
        BeanUtils.copyProperties(couponDto,coupon);
        coupon.setId(uuid);
        return couponService.createCoupon(coupon);
    }

    @GetMapping("/hasCoupon")
    public boolean hasCoupon(int couponId){
        return couponService.hasCoupon(couponId);
    }

    @GetMapping("/useCoupon")
    public boolean useCoupon(int couponId){
        return couponService.useCoupon(couponId);
    }
}
